package com.sth.shishan;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @Author: sitianhong
 * @Description: 网站用户注册是的邮件验证机制
 * @Since: create in 2021/6/13 0013 19:48
 */
public class RedisDemo7 {
    Jedis jedis = new Jedis("127.0.0.1", 6378);

    @Test
    public void demo() {
        takeSendMailTask();
        System.out.println("阻塞式的发送邮件任务");
        enqueueSendMailTask("第一个邮件发送任务");
        System.out.println("阻塞式的发送邮件任务2 " + takeSendMailTask().toString());
    }
    // 让发送邮件任务进入队列
    public void enqueueSendMailTask(String sendMailTask) {
        jedis.lpush("send_mail_task_queue", sendMailTask);
    }
    // 阻塞式获取发送邮件任务
    public List<String> takeSendMailTask() {
        return jedis.brpop(5, "send_mail_task_queue");
    }
}
